package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.RER;
 
 
public class RERDAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public RERDAO(){
    	try {
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	} catch(Exception e){
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all RER instances from the database*/
    @SuppressWarnings("unchecked")
    public List<RER> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<RER> list = session.selectList("RER.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a RER instance from the database*/
    public RER selectById(int rer_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            RER rer = (RER) session.selectOne("RER.getById", rer_no);
            return rer;
        } finally {
            session.close();
        }
    }
 
    /**Updates an instance of RER in the database*/
    public void update(RER rer){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("RER.update", rer);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Insert an instance of RER into the database*/
    public void insert(RER rer){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("RER.insert", rer);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of RER from the database*/
    public void delete(int rer_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("RER.deleteById", rer_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}